/*
 * @Author: zxc
 * @Date: 2020-08-04 08:46:06
 * @LastEditTime: 2020-08-04 10:48:23
 * @LastEditors: zxc
 * @Description: 类型推论
 */

let pn = "zxc";
// pn = 12
let arrs: (number | string)[] = [1, "12"];
// arrs = [2,'b',true]

// 上下文推断， 左推右
// window.onmousedown = (mouseEvent:MouseEvent) => {
//   console.log(mouseEvent);
// }

interface IsInterface {
  name: string;
}
let infos: IsInterface;
const infos1 = { name: "zxc" };
const infos2 = { age: 24 };
const infos3 = { name: "zxc", age: 24 };
// infos = infos1
// infos = infos2
// infos = infos3

/**
 * @Author: zxc
 * @Date: 2020-08-04 09:07:34
 * @func: 函数兼容性
 */
// 参数个数
let x = (a: number) => 0;
let y = (a: number, c: string) => 0;
y = x;
// x = y  //右边的参数个数必须要小于等于左边的参数个数

// 参数类型
let x1 = (a: number) => 0;
let y1 = (a: string) => 0;
// x1 = y1

// 可靠参数和剩余参数
const getSum = (
  arr: number[],
  callback: (...args: number[]) => number
): number => {
  return callback(...arr);
};

getSum([1, 2], (...args: number[]): number => args.reduce((a, b) => a + b, 0));

// 函数参数双向协变（被干掉了一部分）
// tslint:disable-next-line:no-empty
let funcA = (arg: number | string): void => {};
// tslint:disable-next-line: no-empty
let funcB = (arg: number): void => {};
// funcA = funcB
funcB = funcA;

// 返回值类型
let x2 = (): string | number => 0;
let y2 = (): string => "a";
x2 = y2;
// y2 = x2

// 函数重载
function merge(a: number, b: number): number;
function merge(a: string, b: string): string;
function merge(a: any, b: any) {
  return a + b;
}
// tslint:disable-next-line:no-unused-expression
merge("1", "2").length;

function fusm(a: number, b: number): number;
function fusm(a: any, b: any): any {
  return a + b;
}
let funcs = merge;
// funcs = fusm

// 枚举
enum Estatus {
  On,
  Off,
}
enum AniEnum{
  Dog,
  Cat
}
let ss = Estatus.On;
// ss =AniEnum.Dog


/**
 * @Author: zxc
 * @Date: 2020-08-04 10:37:52
 * @func: 类
 */
class D1{
  protected static age: number;
  // tslint:disable-next-line: no-empty
  constructor(public name:string){}
}
class D2 {
  public static age:string
 constructor(public name:string){
 }
}
class D3{
 // tslint:disable-next-line:no-empty
 constructor(public name:number){}
}

let as1 :D1 = new D1('zxc')
let as2 :D2 = new D2('zxc')
let as3 :D3 = new D3(12)
as1 = as2
as2 = as1
// as1 = as3


 class A1{
   protected age!: number;
   // tslint:disable-next-line: no-empty
   constructor(){}
 }
 class A2 extends A1{
  constructor(){
    super()
  }
}
class Aother{
  protected age!:number
  // tslint:disable-next-line:no-empty
  constructor(){}
}
const adeos:A1 = new A2()
// const adeos2:Aother = new A1()




// interface Data<T>{}
// let data1:Data<number> = {}
// let data2:Data<string>= {}
// data1 = data2

interface Data<T>{
  data:T
}
let data1:Data<number> = {data:1}
let data2:Data<string>= {data:'1'}
// data1 = data2